package com.gxwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxwz.medical.domain.Reimburse;

public class ReimburseServlet extends BaseServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String m = req.getParameter("m");// 请求处理动作类型:list:显示列表；get：根据ID读取记录;input:新增数据;add:保存新记录；edit：更新记录
		String url = ERROR_PATH;
		try {
			if ("list".equals(m)) {	
				url="/page/reimburse/reimburse_list.jsp";
			} else if ("input".equals(m)) {
				url="/page/reimburse/reimburse_add.jsp";
			} else if ("get".equals(m)) {
				url="/page/reimburse/reimburse_edit.jsp";			
			}else if ("gets".equals(m)) {
				url="/page/reimburse/reimburse_input.jsp";
				
			} else if ("add".equals(m)) {
				url = this.add(req, resp);
			}else if("edit".equals(m)){
				this.edit(req, resp);
			}else if("del".equals(m)){
				this.del(req, resp);
			}else if("gets".equals(m)){
				this.del(req, resp);
			}
			   process(req, resp, url);
		} catch (Exception e) {
			e.printStackTrace();
		}
		  

	}
	/**
	 * 添加慢病报销
	 * @param req
	 * @param resp
	 * @return
	 * @throws Exception
	 */
	private String add(HttpServletRequest req,HttpServletResponse resp)throws Exception{
		 //1:获取慢病档案信息
		 String cardID=req.getParameter("cardID");
		 String runyear=req.getParameter("runyear");
		 String persname=req.getParameter("persname");
		 String pay=req.getParameter("pay");
		 String paysum=req.getParameter("paysum");
		 String status ="2";
		 //2:实例化慢病证管理模块组件
		 Reimburse model=new Reimburse(cardID,runyear,persname,pay,paysum,status);
		 try{
	  		  model.add();
		      return "/page/reimburse/reimburse_list.jsp";
		  }catch(Exception e){
		  		 throw e;
        	}	
	}
	private void edit(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{

	  	  //1：接收参数
		 String cardID=req.getParameter("cardID");
		 String runyear=req.getParameter("runyear");
		 String persname=req.getParameter("persname");
		 String pay=req.getParameter("pay");
		 String paysum=req.getParameter("paysum");
		 String status =req.getParameter("status");
	  	  //2:构造新慢病信息对象
		 Reimburse model=new Reimburse(cardID,runyear,persname,pay,paysum,status);
			 try{
	  		  model.edit();
	  	      process(req, resp,"/page/reimburse/reimburse_list.jsp");
	  	  }catch(Exception e){
	  		  error(req, resp);
	  	  }
		
	  
		}
	private void del(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{

	  	  //1：接收参数
	  	  String cardID=req.getParameter("id");
	  	  
	  	  //2:构造新慢病信息对象
	  	Reimburse model=new Reimburse();
	  	  try{
	  		  model.del(cardID);
	  		process(req, resp,"/page/reimburse/reimburse_list.jsp");
	  	  }catch(Exception e){
	  		  error(req, resp);
	  	  }
		
	  
		}
}
	
